
================================================================================
YOLOv9 Layer Index Finder
================================================================================

[1] Loading model: models/detect/yolov9-c.yaml

                 from  n    params  module                                  arguments                     
  0                -1  1         0  models.common.Silence                   []                            
  1                -1  1      1856  models.common.Conv                      [3, 64, 3, 2]                 
  2                -1  1     73984  models.common.Conv                      [64, 128, 3, 2]               
  3                -1  1    212864  models.common.RepNCSPELAN4              [128, 256, 128, 64, 1]        
  4                -1  1    164352  models.common.ADown                     [256, 256]                    
  5                -1  1    847616  models.common.RepNCSPELAN4              [256, 512, 256, 128, 1]       
  6                -1  1    656384  models.common.ADown                     [512, 512]                    
  7                -1  1   2857472  models.common.RepNCSPELAN4              [512, 512, 512, 256, 1]       
  8                -1  1    656384  models.common.ADown                     [512, 512]                    
  9                -1  1   2857472  models.common.RepNCSPELAN4              [512, 512, 512, 256, 1]       
 10                -1  1    656896  models.common.SPPELAN                   [512, 512, 256]               
 11                -1  1         0  torch.nn.modules.upsampling.Upsample    [None, 2, 'nearest']          
 12           [-1, 7]  1         0  models.common.Concat                    [1]                           
 13                -1  1   3119616  models.common.RepNCSPELAN4              [1024, 512, 512, 256, 1]      
 14                -1  1         0  torch.nn.modules.upsampling.Upsample    [None, 2, 'nearest']          
 15           [-1, 5]  1         0  models.common.Concat                    [1]                           
 16                -1  1    912640  models.common.RepNCSPELAN4              [1024, 256, 256, 128, 1]      
 17                -1  1    164352  models.common.ADown                     [256, 256]                    
 18          [-1, 13]  1         0  models.common.Concat                    [1]                           
 19                -1  1   2988544  models.common.RepNCSPELAN4              [768, 512, 512, 256, 1]       
 20                -1  1    656384  models.common.ADown                     [512, 512]                    
 21          [-1, 10]  1         0  models.common.Concat                    [1]                           
 22                -1  1   3119616  models.common.RepNCSPELAN4              [1024, 512, 512, 256, 1]      
 23                 5  1    131328  models.common.CBLinear                  [512, [256]]                  
 24                 7  1    393984  models.common.CBLinear                  [512, [256, 512]]             
 25                 9  1    656640  models.common.CBLinear                  [512, [256, 512, 512]]        
 26                 0  1      1856  models.common.Conv                      [3, 64, 3, 2]                 
 27                -1  1     73984  models.common.Conv                      [64, 128, 3, 2]               
 28                -1  1    212864  models.common.RepNCSPELAN4              [128, 256, 128, 64, 1]        
 29                -1  1    164352  models.common.ADown                     [256, 256]                    
 30  [23, 24, 25, -1]  1         0  models.common.CBFuse                    [[0, 0, 0]]                   
 31                -1  1    847616  models.common.RepNCSPELAN4              [256, 512, 256, 128, 1]       
 32                -1  1    656384  models.common.ADown                     [512, 512]                    
 33      [24, 25, -1]  1         0  models.common.CBFuse                    [[1, 1]]                      
 34                -1  1   2857472  models.common.RepNCSPELAN4              [512, 512, 512, 256, 1]       
 35                -1  1    656384  models.common.ADown                     [512, 512]                    
 36          [25, -1]  1         0  models.common.CBFuse                    [[2]]                         
 37                -1  1   2857472  models.common.RepNCSPELAN4              [512, 512, 512, 256, 1]       
 38[31, 34, 37, 16, 19, 22]  1  21725312  models.yolo.DualDDetect                 [80, [512, 512, 512, 256, 512, 512]]
yolov9-c summary: 962 layers, 51182080 parameters, 51182048 gradients, 239.9 GFLOPs

    ✓ Model loaded successfully
    Total layers: 39

[2] Scanning layers for feature maps...

================================================================================
Finding P3, P4, P5 Layer Indices for YOLOv9
================================================================================

Input: torch.Size([1, 3, 640, 640])

Scanning all layers...

Layer  Module                              Output Shape                   H     W     Ch    
-----------------------------------------------------------------------------------------------
0      Silence                             (1, 3, 640, 640)               640   640   3       
1      Conv                                (1, 64, 320, 320)              320   320   64      
2      Conv                                (1, 128, 160, 160)             160   160   128     
3      RepNCSPELAN4                        (1, 256, 160, 160)             160   160   256     
4      ADown                               (1, 256, 80, 80)               80    80    256     ← P3 CANDIDATE
5      RepNCSPELAN4                        (1, 512, 80, 80)               80    80    512     ← P3 CANDIDATE
6      ADown                               (1, 512, 40, 40)               40    40    512     ← P4 CANDIDATE
7      RepNCSPELAN4                        (1, 512, 40, 40)               40    40    512     ← P4 CANDIDATE
8      ADown                               (1, 512, 20, 20)               20    20    512     ← P5 CANDIDATE
9      RepNCSPELAN4                        (1, 512, 20, 20)               20    20    512     ← P5 CANDIDATE
10     SPPELAN                             (1, 512, 20, 20)               20    20    512     ← P5 CANDIDATE
11     Upsample                            (1, 512, 40, 40)               40    40    512     ← P4 CANDIDATE
12     Concat                              (1, 1024, 40, 40)              40    40    1024    ← P4 CANDIDATE
13     RepNCSPELAN4                        (1, 512, 40, 40)               40    40    512     ← P4 CANDIDATE
14     Upsample                            (1, 512, 80, 80)               80    80    512     ← P3 CANDIDATE
15     Concat                              (1, 1024, 80, 80)              80    80    1024    ← P3 CANDIDATE
16     RepNCSPELAN4                        (1, 256, 80, 80)               80    80    256     ← P3 CANDIDATE
17     ADown                               (1, 256, 40, 40)               40    40    256     ← P4 CANDIDATE
18     Concat                              (1, 768, 40, 40)               40    40    768     ← P4 CANDIDATE
19     RepNCSPELAN4                        (1, 512, 40, 40)               40    40    512     ← P4 CANDIDATE
20     ADown                               (1, 512, 20, 20)               20    20    512     ← P5 CANDIDATE
21     Concat                              (1, 1024, 20, 20)              20    20    1024    ← P5 CANDIDATE
22     RepNCSPELAN4                        (1, 512, 20, 20)               20    20    512     ← P5 CANDIDATE
26     Conv                                (1, 64, 320, 320)              320   320   64      
27     Conv                                (1, 128, 160, 160)             160   160   128     
28     RepNCSPELAN4                        (1, 256, 160, 160)             160   160   256     
29     ADown                               (1, 256, 80, 80)               80    80    256     ← P3 CANDIDATE
30     CBFuse                              (1, 256, 80, 80)               80    80    256     ← P3 CANDIDATE
31     RepNCSPELAN4                        (1, 512, 80, 80)               80    80    512     ← P3 CANDIDATE
32     ADown                               (1, 512, 40, 40)               40    40    512     ← P4 CANDIDATE
33     CBFuse                              (1, 512, 40, 40)               40    40    512     ← P4 CANDIDATE
34     RepNCSPELAN4                        (1, 512, 40, 40)               40    40    512     ← P4 CANDIDATE
35     ADown                               (1, 512, 20, 20)               20    20    512     ← P5 CANDIDATE
36     CBFuse                              (1, 512, 20, 20)               20    20    512     ← P5 CANDIDATE
37     RepNCSPELAN4                        (1, 512, 20, 20)               20    20    512     ← P5 CANDIDATE

================================================================================
Summary - Feature Pyramid Candidates
================================================================================

🔍 P3 Candidates (80x80):
   Layer   4:  256 channels (ADown)
   Layer   5:  512 channels (RepNCSPELAN4)
   Layer  14:  512 channels (Upsample)
   Layer  15: 1024 channels (Concat)
   Layer  16:  256 channels (RepNCSPELAN4)
   Layer  29:  256 channels (ADown)
   Layer  30:  256 channels (CBFuse)
   Layer  31:  512 channels (RepNCSPELAN4)
   ✓ RECOMMENDED: Layer 31

🔍 P4 Candidates (40x40):
   Layer   6:  512 channels (ADown)
   Layer   7:  512 channels (RepNCSPELAN4)
   Layer  11:  512 channels (Upsample)
   Layer  12: 1024 channels (Concat)
   Layer  13:  512 channels (RepNCSPELAN4)
   Layer  17:  256 channels (ADown)
   Layer  18:  768 channels (Concat)
   Layer  19:  512 channels (RepNCSPELAN4)
   Layer  32:  512 channels (ADown)
   Layer  33:  512 channels (CBFuse)
   Layer  34:  512 channels (RepNCSPELAN4)
   ✓ RECOMMENDED: Layer 34

🔍 P5 Candidates (20x20):
   Layer   8:  512 channels (ADown)
   Layer   9:  512 channels (RepNCSPELAN4)
   Layer  10:  512 channels (SPPELAN)
   Layer  20:  512 channels (ADown)
   Layer  21: 1024 channels (Concat)
   Layer  22:  512 channels (RepNCSPELAN4)
   Layer  35:  512 channels (ADown)
   Layer  36:  512 channels (CBFuse)
   Layer  37:  512 channels (RepNCSPELAN4)
   ✓ RECOMMENDED: Layer 37

================================================================================
✅ FINAL RECOMMENDATION
================================================================================

Update extract_features_for_stata() with these indices:

```python
P3_INDEX = 31  # [512 channels, 80x80]
P4_INDEX = 34  # [512 channels, 40x40]
P5_INDEX = 37  # [512 channels, 20x20]
```

And update setup_stata() with channel configuration:

```python
yolo_channels = [512, 512, 512]
```

================================================================================

[3] Verifying indices by extracting features...
    ✓ P3 extracted: torch.Size([1, 512, 80, 80])
    ✓ P4 extracted: torch.Size([1, 512, 40, 40])
    ✓ P5 extracted: torch.Size([1, 512, 20, 20])

================================================================================
✅ SUCCESS! All feature levels verified!
================================================================================

Copy these values to your code:

1. In extract_features_for_stata():
   P3_INDEX = 31
   P4_INDEX = 34
   P5_INDEX = 37

2. In setup_stata():
   yolo_channels = [512, 512, 512]

================================================================================

(yolov9) wrf@wrf:~/Dara/yolov9-main$ 